package com.hrbxlh.virtualization.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * 容器状态枚举
 *
 * @author cheer
 */
public enum ContainerStatusEnum {

    RUNNING(1, "运行"),
    STOPPED(2, "停止"),
    STARTING(3, "正在启动"),
    STOPPING(4, "正在停止");


    private Integer code;
    private String message;

    ContainerStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static String codeToMessage(Integer code) {
        for (ContainerStatusEnum containerStatusEnum : ContainerStatusEnum.values()) {
            if (containerStatusEnum.getCode().equals(code)) {
                return containerStatusEnum.getMessage();
            }
        }
        return null;
    }

    public static ContainerStatusEnum getByNameIgnoreCase(String name){
        try {
            return ContainerStatusEnum.valueOf(StringUtils.upperCase(name));
        } catch (IllegalArgumentException e) {
            return null;
        }
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
}
